package com.heyqing.topic.InorderTraversal_0094;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * ClassName:InorderTraversal
 * Package:com.heyqing.topic.InorderTraversal_0094
 * Description:
 *
 * @Date:2024/9/12
 * @Author:Heyqing
 */
public class InorderTraversal {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result  = new ArrayList<>();
        inorderTraversalRecursive(root,result);
        return result;
    }

    private void inorderTraversalRecursive(TreeNode root,List<Integer> result) {
        if (Objects.isNull(root)){
            return;
        }
        inorderTraversalRecursive(root.left,result);
        result.add(root.val);
        inorderTraversalRecursive(root.right,result);
    }
}
